/**
 * 该js用来定义firbreath插件的回调方法处理.
 */

/**
 *回调函数: *@param[in] type:1-关闭，2-选中，3-双击(放大/缩小)
 */
function VideoCallback(type, videoid, status) {
    var pluginObj  =   $("#"+videoid)[0].videoObj;
    var pluginHandleClass  = pluginObj.getHandleClass();//视频小组件处理类
    var ContainerHandleClass  = $("#"+videoid)[0].container //videocontainer的处理类
    switch (type) {
        /*case 0://初始化成功后开始播放
            pluginHandleClass._isInitSucess = true;
            pluginHandleClass.startplay();
            ContainerHandleClass.returnCallback();
            break;*/
        case 1: //关闭
        	if(ContainerHandleClass._closeable){
                ContainerHandleClass.delVideo(pluginObj);
        	}
            break;
        case 2: //选中
        	var videoObj = null;
        	for(var i=0;i<ContainerHandleClass.videosObj.length;i++){
        		if(ContainerHandleClass.videosObj[i] == pluginObj){
                    ContainerHandleClass.setChooseVideos(ContainerHandleClass.videosObj[i]);
        			break;
        		}
        	}
            break;
        case 3://双击(放大/缩小)
        	var iszoomin =pluginHandleClass._isZoomIn;  //获取当前视频组件的参数
            if (iszoomin) {
                ContainerHandleClass.zoomMid(videoid);
                pluginHandleClass._isZoomIn = false;
                pluginHandleClass.setWndSize(ContainerHandleClass._width,ContainerHandleClass._height)
           
            } else {
                ContainerHandleClass.zoomIn(videoid);
                pluginHandleClass._isZoomIn = true;
                pluginHandleClass.setWndSize(ContainerHandleClass.smwidth,ContainerHandleClass.smheight);
            }
            break;
        case 4: //状态返回
            if(status.indexOf("历史") > -1){
            	pluginHandleClass._playStatus = false;
        	}else{
        		pluginHandleClass._playStatus = true;
        		pluginHandleClass._playSpeed = 5; //初始化速度
        	}
            break;
        case 7: //截图
            ContainerHandleClass.screenShotPrompt(pluginHandleClass,status);
        	break;
        case 10: //打开声音
        	pluginHandleClass._soundStatus = true;
            ContainerHandleClass.closeOtherSound(pluginObj);
            break;
        case 11: //关闭声音
        	pluginHandleClass._soundStatus = false;
            break;
        case 15:  //快放
        case 16:  //慢放       	
        	var start = status.indexOf("currentspeed")+13;
        	var end = status.indexOf("error")-1;
        	var spaySpeed = parseInt(status.substring(start,end));
        	pluginHandleClass._playSpeed  = spaySpeed;
        	break;
        case 20:  //开启人脸识别
        case 21:  //关闭人脸识别
        	pluginHandleClass.changeFaceState(type);
        	break;
    }
}
//  3D 回调
function pushMsgToWeb(pluginId, params){
    var params = JSON.parse(params);
    var container = application.getElementById(pluginId); // 3D插件组件ID
    var HandleClass = container.getHandleClass();
    var videoComponent,monitorComponent,broadcastComponent,doorComponent;  // 安防设备组件
    //判断是否需要打开视频，如果需要打开视频，先判断是否存在视频组件，如果存在就设置打开当前视频，如果不存在就加载视频组件再设置视频
	if(params.method == "do_video_linkage_msg"){
        if($('.layout_video',container.getHTML()).length > 0){
            //  取video page的处理类
            videoComponent = container.getElementById("threeD-device").getElementById("layout_video").getHandleClass();
            videoComponent.initVideo({"data":{"resid":params.paramlist.uuid}});
        }else{
            var videoDetail = container.getElementById("threeD-device").addItem('Component',{
                "src" : "/platform.threedim/comp/deveicecomponent/layoutvideo/LayoutVideo.html",
                "class" : "layout_video device-item"
            })
            //  HandleClass.setHasOpenArray(videoDetail);
            //  取video page的处理类
            videoComponent = container.getElementById('layout_video').getHandleClass();
            videoComponent.initVideo({"data":{"resid":params.paramlist.uuid}});
        }
    }
    //  对讲
    if(params.method == "do_talkback_linkage_msg"){
        if($('.layout_monitor',container.getHTML()).length > 0){
            //  取monitor page的处理类
            monitorComponent = container.getElementById('layout_monitor').getHandleClass();
            monitorComponent.initMonitor({"data":{"resid":params.paramlist.uuid}});
        }else{
            var monitorDetail = container.getElementById('threeD-device').addItem('Component',{
                "src" : "/platform.threedim/comp/deveicecomponent/layoutmonitor/LayoutMonitor.html",
                "class" : "layout_monitor device-item"
            })
            // HandleClass.setHasOpenArray(monitorDetail);
            //  取monitor page的处理类
            monitorComponent = container.getElementById('layout_monitor').getHandleClass();
            monitorComponent.initMonitor({"data":{"resid":params.paramlist.uuid}});
        }
    }
    //  广播
    if(params.method == "do_broadcast_linkage_msg"){
        if($('.layout_broadcast',container.getHTML()).length > 0){
            //  取broadcast page的处理类
            broadcastComponent = container.getElementById('layout_broadcast').getHandleClass();
            broadcastComponent.initMap({"dataList":[{"resid":params.paramlist.uuid}]});
        }else {
            var broadcastDetail = container.getElementById('threeD-device').addItem('Component',{
                "src" : "/platform.threedim/comp/deveicecomponent/layoutbroadcast/LayoutBroadcast.html",
                "class" : "layout_broadcast device-item"
            })
            // HandleClass.setHasOpenArray(broadcastDetail);
            //  取broadcast page的处理类
            broadcastComponent = container.getElementById('layout_broadcast').getHandleClass();
            broadcastComponent.createBroadcast({"dataList":[{"resid":params.paramlist.uuid}]});
            console.log(params.paramlist.uuid)
        }
    }
    //  门禁
    if(params.method == "do_doorcheck_linkage_msg"){
        if($(".layout_door",container.getHTML()).length > 0){
            //  取door page的处理类
            doorComponent = container.getElementById('layout_door').getHandleClass();
            doorComponent.initData({"data":{"resid":params.paramlist.uuid}});
        }else {
            var doorDetail = container.getElementById('threeD-device').addItem('Component',{
                "src" : "/platform.threedim/comp/deveicecomponent/layoutdoor/LayoutDoor.html",
                "class" : "layout_door device-item"
            })
            // HandleClass.setHasOpenArray(doorDetail);
            //  取door page的处理类
            doorComponent = container.getElementById('layout_door').getHandleClass();
            doorComponent.initData({"data":{"resid":params.paramlist.uuid}});
        }
    }
    //  实时点位
    if(params.method == "real_scene_msg"){
        //  获取minimap 的处理类
        var minimapComponent = container.getElementById('threeD-miniMap').getHandleClass();
        minimapComponent.setLiveScene(params.paramlist);
    }
    //  启动系统回调
    if(params.method == "do_launch_system" && params.result == 1){
        setTimeout(function(){
            var loadSenceResult = HandleClass.videoHandler("3d_scene_op","do_load_scene",{"scene_uuid":HandleClass._3dFlag});
            console.log(loadSenceResult,"场景加载");
        }, 500);
    }
    //  联动报警
    if(params.method == "do_load_scene" && params.result == 1){
        HandleClass.doOperation();
    }
}
/**
 *中电兴发监听对讲回调接口
 */
function zdxhCallback(type, pluginId, result) {
    var container = application.getElementById(pluginId);
    var res = eval('(' + result + ')');
    switch (type) {
    	case 999: //登录结果通知
		  if(res.result){
		      container.loginIn();
		  }else{
		      container.setLoginState("nologin");
		  }
		break;
        case 1002: //登录结果通知
            if(res.result){
                container.setLoginState("login");
            }else{
                container.setLoginState("nologin");
            }
        break;
        case 1003: //登出结果通知
            if(res.result){
                container.setLoginState("logout");
            }
            break;
		case 1004: //打开声音结果通知
			{
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
		case 1005: //关闭声音结果通知
			{	
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
		case 1007: //关门结果通知
			var data = {};
			data["成功"] = true;
			data["结果"] = res.result;
			data["操作类型"] = "关门";
			container.callBackDoorStatus(data);
			break;
		case 1008: //开门结果通知
			var data = {};
			data["成功"] = true;
			data["结果"] = res.result;
			data["操作类型"] = "开门";	
			container.callBackDoorStatus(data);
			break;
		case 1009: //获取门状态
			{
				//其中status的值代表门状态；status为"1"代表门开，为"0"代表门关
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
		case 1010: //打开对讲结果通知
			{
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
		case 1011: //关闭对讲结果通知
			{
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
		case 1012: //打开广播结果通知
			{
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
		case 1013: //关闭广播结果通知
			{
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
		case 1014: //打开文件广播结果通知
			{
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
		case 1015: //关闭文件广播结果通知
			{
				//TODO:{result:true,status:""}或者{result:false,status:""}
			}break;
    }
}

/**
 * 插件组装处理函数
 * @param plugin  插件对象
 * @param capability   能力
 * @param method  方法
 * @param params 参数
 */
function pluginHander(plugin,capability,method,params,func){
    var param = {};
    if(capability){
        param["capability"] = capability;
    }
    if(method){
        param["method"] = method;
    }
    if(params != null){
        param["paramlist"] = params;
    }
    var paramString = JSON.stringify(param);
    var result = plugin.handleWebRequest(paramString,function(result){
        var res = eval('(' + result + ')');
        if(func){
            func(res);
        }
    });
   return  eval('(' + result + ')');
}
